<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\facade\Builder;
//该文件为自动生成，请按需修改
class Freight extends Base
{
    //所有定义变量均为演示，请根据实际需求更改

    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Freight';

    //关联模型
    protected array $hasOne = ['area'];
    //数据排序，支持多个
    protected array $sort = ['sort' => 'asc'];

    public function index(): string
    {
        // $list= \app\common\model\Area::where(['level'=>1])->order('id asc')->select();
        // foreach($list as $k=>$v){
        //     $data['area_code']=$v['code'];
        //     $data['create_time']=time()+20;
        //     $data['update_time']=time()+20;
        //     $data['sort']=$k+1;
        //     $data['money']=20;
        //     $this->model::insert($data);
        // }
        //构建表格数据
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'title' => '全选', 'fixed' => 'left'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'province', 'title' => '省','templet' => '<div>{{d.area.province}}</div>'])
            ->addColumn(['field' => 'money', 'title' => '运费', 'modify' => '2,input','templet' => '#sort_money', 'width' => 120])
            ->addColumn(['field' => 'sort', 'title' => '排序', 'modify' => '2,input', 'templet' => '#sort_sort', 'width' => 120])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 200])
            ->addRightButtons([/*'edit' => ['size' => '1000,1000'],*/ 'delete'])
            ->addTopButtons([/*'add' => ['size' => '1000,1000'], */'deleteAll'])
            ->addSearch([])
            ->addSortTool([['name' => 'sort', 'pk' => $this->pk, 'url' => url('update')->build()],['name' => 'money', 'pk' => $this->pk, 'url' => url('update')->build()]])
            ->fetch();
    }
}
